<?php
require_once 'technics/DAO.php';
DAO::connect("bugreport");

class Main extends BaseController{
	public function index(){
		echo "page index de Main";
	}
	public function applications(){
		var_dump(DAO::getAll("UseCase"));
	}
	
	public function relex(){
		$app=new Application();
		$app->setLibelle("Essai d'application");
		$app->setId(12888);
		var_dump(DAO::getPropertiesAndValues($app));
	}
	
	public function annot(){
		var_dump(Reflexion::getAnnotationMember("Application", "useCases", "Column"));
	}
	
	public function id(){
		$app=new Application();
		$app->setLibelle("Essai d'application");
		$app->setId(12888);
		var_dump(OrmUtils::getKeyFieldsAndValues($app));
	}
	
	public function appli(){
		$app=DAO::getOne("Application", "id=4");
		DAO::getOneToMany($app, "useCases");
		var_dump($app);
		/*$app2=DAO::getOne("Application", "id=3");
		DAO::getOneToMany($app2, "useCases",DAO::getAll("UseCase"));
		var_dump($app2);*/
	}
	
	public function useCase(){
		$app=new Application();
		$app->setLibelle("Essai d'application");
		$app->setId(12888);
		$uc=new UseCase();
		$uc->setCode("AAA");
		$uc->setApplication($app);
		var_dump(OrmUtils::getManyToOneMembersAndValues($uc));
		var_dump(Reflexion::getPropertiesAndValues($uc));
	}
	
	public function delete(){
		$app=new Application();
		$app->setLibelle("Essai d'application");
		$app->setId(1);
		if(DAO::delete($app)){
			echo "Suppression";
		}else{
			echo "Supression impossible";
		}
	}
	
	public function add(){
		$app=new Application();
		$app->setLibelle("BugReport");
		//$app->setId(2);
		if(DAO::insert($app)){
			echo "Ajout";
		}else{
			echo "Ajout impossible";
		}
	}
	public function addUc(){
		$app=new Application();
		$app->setLibelle("GSB");
		$app->setId(2);
		
		$uc=new UseCase();
		$uc->setCode("A");
		$uc->setLibelle("Ajout d'un bug");
		$uc->setApplication($app);
		if(DAO::insert($uc)){
			echo "Ajout";
		}else{
			echo "Ajout impossible";
		}
	}
	public function update(){
		$app=new Application();
		$app->setLibelle("BugReport 2");
		$app->setDescriptif("Essai de descriptif\nsur plusieurs lignes");
		$app->setId(4);
		$app->setDateCreation(date("Y-m-d H:i:s",time()));
		if(DAO::update($app)){
			echo "Modification";
		}else{
			echo "Modification impossible";
		}
	}
}